package com.example.header;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2024-03-02
 * Time: 16:14
 *
 * 获取请求头
 */

@Controller
@ResponseBody
@RequestMapping("/header")
public class HeaderController {


    // @RequestHeader("Host")，获取请求头中的 Host 键值对的值
    @GetMapping("/data")
    public String data(@RequestHeader("Host") String host) {
        System.out.println("Host:" + host);
        return host;
    }
}
